package com.konne.nightmare.FastPublicOpinion.ui.information.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.konne.nightmare.FastPublicOpinion.R;
import com.konne.nightmare.FastPublicOpinion.base.BaseMvpFragment;
import com.konne.nightmare.FastPublicOpinion.bean.MembersBean;
import com.konne.nightmare.FastPublicOpinion.mvp.presenter.CGMAppointPersenter;
import com.konne.nightmare.FastPublicOpinion.mvp.view.ICGMAppointView;
import com.konne.nightmare.FastPublicOpinion.ui.dialog.CGroupManagerDialog;
import com.konne.nightmare.FastPublicOpinion.ui.information.activity.GroupManagerActivity;
import com.konne.nightmare.FastPublicOpinion.ui.information.adapter.CGMStudentAdapter;
import com.konne.nightmare.FastPublicOpinion.utils.LoadProgressDialog;

import java.util.List;

import butterknife.BindView;

/**
 * Create by ws.
 * on Data:2022/1/25  Time:下午 5:07.
 * description: ** .
 */
public class CGMAppointFragment extends BaseMvpFragment<ICGMAppointView, CGMAppointPersenter> implements ICGMAppointView , View.OnClickListener {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private CGMStudentAdapter mAdapter;
    public static CGMAppointFragment getInstance(){
        return new CGMAppointFragment();
    }
    @Override
    protected CGMAppointPersenter createPresenter() {
        return new CGMAppointPersenter();
    }

    @Override
    public LoadProgressDialog getLoadDialog() {
        return null;
    }

    @Override
    public void cancelLoadDialog() {

    }

    @Override
    public int getLayout() {
        return R.layout.frag_cgm_appoint;
    }

    @Override
    public void initView() {
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        findViewById(R.id.stv_move_student).setOnClickListener(this::onClick);
        findViewById(R.id.stv_manager).setOnClickListener(this::onClick);
        findViewById(R.id.stv_add_group).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.stv_manager:
                new CGroupManagerDialog(getContext()).setcGroupManagerListener(new CGroupManagerDialog.CGroupManagerListener() {
                    @Override
                    public void fun(int type) {
                        if(type==0){
                            mPresenter.renameGroupName();
                        }else {
                            mPresenter.delGroup();
                        }
                    }
                }).show();
                break;
            case R.id.stv_add_group:
                mPresenter.addGroup();
                break;
            case R.id.stv_move_student:
                GroupManagerActivity.start(0);
                break;
        }
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        mPresenter.init();
    }

    @Override
    public void addGroup(String txt) {
        LinearLayout ll_group=findViewById(R.id.ll_group);
        ViewGroup view= (ViewGroup) LayoutInflater.from(getContext()).inflate(R.layout.item_cgm_group,null);
        TextView title= (TextView) ((ViewGroup)view.getChildAt(0)).getChildAt(0);
        title.setText(txt);
        ll_group.addView(view);
    }

    @Override
    public void updataStudent(List<MembersBean> data, int size) {
        if(mAdapter==null){
            mAdapter=new CGMStudentAdapter(data);
            recyclerView.setAdapter(mAdapter);
        }else {
            mAdapter.setNewData(data);
        }

    }
}
